package common;

import evthandler.EventMessage;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JPanel;

/**
 *
 * @author Casper, Dennis, Jackie, Jakob
 * @version 1.00
 */
public class ImagePanel extends JPanel {

    private BufferedImage image;
    private Dimension dimension;

    /**
     *
     * @param fileName
     */
    public ImagePanel(String fileName) {
        try {
            image = ImageIO.read(new File(fileName));
        } catch (IOException ex) {
            new EventMessage("File IO error", "There was an IO error").showException(ex);
        }
        dimension = new Dimension(image.getWidth(), image.getHeight());
        this.setPreferredSize(dimension);
        this.setSize(dimension);
    }

    /**
     *
     * @param g
     */
    @Override
    public void paintComponent(Graphics g) {
        g.drawImage(image, 0, 0, null);
    }
}
